<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9">
<title>SM Students Taking Non-SM Courses Details</title>
<SCRIPT TYPE="text/javascript" src= "../../commonutils/util/util.js"> </SCRIPT>
</head>
<style type="text/css">

</style>
<body>
<?php include '../../checkPCandVPC.php'; ?>
<?php include 'top.html'; ?>
<?php include 'notifier.php'; ?>
<?php include '../../authorization_check.php'; ?>

<?php
  session_start();
  $programCodeSpecial = $_SESSION['programCode'];
  $semesterIDSpecial = $_SESSION['semesterID'];
?>
  
  
  <?php
  require_once '../../commonutils/util/PageTemplate.php';
  require_once '../../commonutils/db/DBConnectionManager.php';

  //global variables
  $totalPayment = 0;
  $count = 0;
  $dcount = 0;
  $totalCredit = 0;
  $totalPayment = 0;
  $depSC;
  $bosrow = 0;
  //$dep; 

  function listSMStudTakingNonProgCourseForm($webPage){
  $webPage->addContent("<form name='listSMStudTakingNonProgCoursesForm' method='post' action=''>");				
  }

  //FIND THE NUMBER OF RECORDS AND NUMBER OF DIFFERENT DEPARTMENTS GLOBALY



  $result = DBConnectionManager::query("SELECT DISTINCT
  enrollment.studentID,
  enrollment.semesterID,
  enrollment.sectionID,
  course.courseName,
  course.courseCode,
  student.lastName,
  student.firstName,
  section.semesterID,
  section.sectionID,
  section.courseCode,
  student.programCode,
  course.credit,
  program.longName,
  student.studentID,
  course.programCode
FROM
  enrollment,
  course,
  student,
  section,
  program
WHERE
  enrollment.studentID = student.studentID AND
  enrollment.semesterID = section.semesterID AND
  enrollment.sectionID = section.sectionID AND
  section.courseCode = course.courseCode AND
  student.programCode = program.programCode AND
  student.programCode LIKE '9050' AND
  section.courseCode <> '9050%'
GROUP BY
  enrollment.studentID,
  enrollment.semesterID,
  enrollment.sectionID,
  section.courseCode
ORDER BY
  course.programCode
  ");
		
		//-----------------------------------------------------------
		//ERRRRRRRRRRRRRRRRRRRROOOOOOOOOOOOOOOOOOOOOOR
		//print ("Error: (" . mysql_errno() . ") " . mysql_error());
    //-----------------------------------------------------------
    
    //$row = mysql_fetch_assoc($result);
      $dep[$dcount] = 'xx';
      
      //$names = $row['firstName'];
      //echo "$names";
      $depSC[$dcount] = 1;
      
      //echo "dcount :".$dcount."<br>";
      //echo "depSC[0] :".$depSC[0]."<br>";
      
      
      
      while($row = mysql_fetch_assoc($result)){
      //$names2 = $row['firstName'];
      $code = $row['programCode'];
      $lName= $row['longName'];
      //echo "code:".$code."<br>";
      //echo "LongName:".$lName."<br>";
      
      if( $row['programCode'] != $dep[$dcount] ){
      //echo "girdim"."<br>";
          $depNo[$dcount] = $row['programCode'];
          //echo "depNO[dcount]: ".$depNo[$dcount]."dcount: "."$dcount"."<br>";
          
      		$depN[$dcount] = $row['longName'];
      		//echo "depN[dcount]: ".$depN[$dcount]."dcount: "."$dcount"."<br>";
      		$dcount++;
      		//echo "dcount: "."$dcount"."<br>";
      		
            $depSC[$dcount] = 0;
            //echo "depSC[".$dcount."]=".$depSC[$dcount]."<br>";
            $dep[$dcount] = $row['programCode'];
            $depN[$dcount] = $row['longName'];
            
            }			
        $depSC[$dcount]++;
        
        //echo "depSC[".$dcount."]=".$depSC[$dcount]."<br>";
      }
    /*echo "onceki dep: ";
    echo "$dep[0]";
    echo "ustteki count: ";
    echo "$count"+1;
    echo "ustteki dcount: ";
    echo "$dcount"+1;*/

  function listStudents($webPage, $loopNo){
    
    global $count, $dcount, $dep, $depN, $totalCredit, $totalPayment,$bosrow, $depSC ;
    $totalCredit = 0;
    $totalPayment = 0;
    
    //echo "loopNoUst:"."$loopNo"."<br>";
    
    //echo "sonraki dep: ";
    //echo "$dep[0]";
      
    $webPage->addContent("<form name='listSMStudTakingNonProgCourseForm' method='post'>");
    $webPage->addContent("<table align = 'center' border=1 name='listSMStudTakingNonProgCourseTable'>");
    $webPage->addContent("<tr>");
      $webPage->addContent("<th>Student ID</th>");
      $webPage->addContent("<th>Name</th>");
      $webPage->addContent("<th>Surname</th>");
      $webPage->addContent("<th>Department</th>");
      $webPage->addContent("<th>Course Code</th>");
      $webPage->addContent("<th>Course Name</th>");
      $webPage->addContent("<th>Course Credit</th>");
      $webPage->addContent("<th>Total Payment (YTL)</th>");
    $webPage->addContent("</tr>");
    
    //echo "dep[loopNo]: ";
    //echo "$dep[$loopNo]";
    
      $result2 = DBConnectionManager::query("SELECT DISTINCT
  enrollment.studentID,
  enrollment.semesterID,
  enrollment.sectionID,
  course.courseName,
  course.courseCode,
  student.lastName,
  student.firstName,
  section.semesterID,
  section.sectionID,
  section.courseCode,
  student.programCode,
  course.credit,
  program.longName,
  student.studentID,
  course.programCode
FROM
  enrollment,
  course,
  student,
  section,
  program
WHERE
  enrollment.studentID = student.studentID AND
  enrollment.semesterID = section.semesterID AND
  enrollment.sectionID = section.sectionID AND
  section.courseCode = course.courseCode AND
  student.programCode = program.programCode AND
  student.programCode LIKE '9050' AND
  section.courseCode <> '9050%'
GROUP BY
  enrollment.studentID,
  enrollment.semesterID,
  enrollment.sectionID,
  section.courseCode
ORDER BY
  course.programCode
  "); 

  
    //echo "for oncesi: ";
    //echo "$count"+1;
    $bosrow = 0;
    //echo "bosrow1:".$bosrow."<br>";
    
    //echo "loopNo:".$loopNo."<br>";
    
    
    //echo "loopNo:".$loopNo."<br>";
    
    for($l=0; $l < $loopNo ; $l++){
    //echo "depSC[LLLLL]".$depSC[$l]."<br>";
    $bosrow = $bosrow + $depSC[$l];
    
    
    
    //for($k =0; $k <= $depSC[$l]; $k++){
    //  $bosrow ++;
    //  echo $k;
    //echo "bosrow2:".$bosrow."<br>";
    //}
    }
    //echo "bosrow: ".$bosrow."<br>";
   //echo "bosRow Sayisi for:".$loopNo.": ".$bosrow."<br>";
    $i = 0;
    $j = 0;
    while($row2 = mysql_fetch_assoc($result2))
    {
      if($i < $bosrow)
        {
          //echo "if'e kafam girdi!!"."<br>";
        }
        
        else{
        //echo "depSC[loopNo]:".$depSC[$loopNo]."<br>";
        //echo "j:".$j."<br>";
        if($j < $depSC[$loopNo]){
        
        //echo "if2'ye de kafam girdi!!!"."<br>";
        $studentID = $row2['studentID'];
        //echo "$studentID"." "; 
        $firstName = $row2['firstName']; 
        //echo "$firstName"." "; 
        $lastName = $row2['lastName']; 
        //echo "$lastName"." "; 
        $department = $row2['longName'];
        //echo "$department"." "; 
        $courseCode = $row2['courseCode'];
        //echo "$courseCode"." "; 
        $courseName = $row2['courseName'];
        //echo "$courseName"." "; 
        $credit = $row2['credit'];
        //echo "$credit"." "; 
        $totalCredit +=$credit;
        //echo "$totalCredit"." "; 
        $totalStudentPayment = 300 * $credit;
        //echo "$totalStudentPayment"." "; 
        $totalPayment += $totalStudentPayment;
        //echo "$totalPayment"."<br>"; 
        $webPage->addContent("<tr>");
          $webPage->addContent("<td>$studentID</td>");
          $webPage->addContent("<td>$firstName</td>");
          $webPage->addContent("<td>$lastName</td>");
          $webPage->addContent("<td>$department</td>");
          $webPage->addContent("<td>$courseCode</td>");
          $webPage->addContent("<td>$courseName</td>");
          $webPage->addContent("<td align = 'center'>$credit</td>");
          $webPage->addContent("<td align = 'center'>$totalStudentPayment</td>");
          //$webPage->addContent("<td>$totalPaymentForACourse</td>");	
        $webPage->addContent("</tr>");
        //$count++;
      
    
    
    
    $j ++;
    }
    else
    {
    break;
    }
    
    }
    $i ++;
  }
  
  
  $webPage->addContent("<tr><td colspan = 6/></td><th align= left><u>Total Payment</u></th><th align=center>$totalPayment</th>");
    $webPage->addContent("<tr><td colspan = 6/></td><th align= left><u>Total Credit</u></th><th align=center>$totalCredit</th>");
    $webPage->addContent("</tr>");
    $webPage->addContent("</table>");
    $webPage->addContent("<table align = 'center'><tr>");
    $webPage->addContent("<td>");
    $webPage->addContent("</td>");
    $webPage->addContent("<td>");
    $webPage->addContent("</td>");
    $webPage->addContent("</tr></table></form>");
  }


  //BURASI SAYFANIN BASLIGININ VE FOOTER'ININ OLUSTURULDUGU YER

  $webPage = new Page();


  //addJavaScripts($webPage);

  $webPage->addHeader('Software Management Students Taking Non-Program Courses Details');

  //$lc = $dcount + 1;
  //echo "en alttaki lc: ";
  //echo "$lc";
    
  listSMStudTakingNonProgCourseForm($webPage);

    $dc = $dcount;
    /*
    for($forcount=0;$forcount<$dcount;$forcount++){
    echo "depno:".$depNo[$forcount]."<br>";
    }
    */
    
    
    /*echo "en alttaki dcount: ";
    echo "$dc";
    echo "<br>";
    echo $bosrow;*/
    //echo "dc"."$dc";
    
  if($dc == 0){
      $webPage->addCenterContent("!!! THERE ISN'T ANY SM STUDENT TAKING NON-PROGRAM COURSES !!!");
    }else{
  for($j = 0; $j < $dc; $j++){
      //echo "dc: "."$dc"."<br>";
      
      
      //-----------------------------------------------
      
      //--------------ASAMA 1-----------------
      $result = DBConnectionManager::query("SELECT longName
      FROM program
      WHERE programCode = '$depNo[$j]'
      ");
      
      //--------------ASAMA 2-----------------
      $row = mysql_fetch_assoc($result);
      $programLongName = $row['longName'];
      //-----------------------------------------------
      
      
      $webPage->addCenterContent("Courses Taken from $programLongName Department");
      listStudents($webPage,$j);		
      
      
      }
    }
  $webPage->addFooter(date('Y'), 'IIPIS');
  echo $webPage->get();

  ?>
  <?php include 'bottom.php' ?>


</body>


</html>